package edu.siu.math.egut.util;

import java.util.ArrayList;
import java.util.List;

import org.jscience.mathematics.structure.GroupMultiplicative;

/**
 * This class represents an element of the Weyl group of one of the five
 * exceptional groups.
 * 
 * @author Joe Pleso
 *
 */
public class WeylElement implements GroupMultiplicative<WeylElement> {

    private final ExceptionalGroup group;
    private final List<Integer> word;
    
    /**
     * Get an element from the Weyl group. Can only be a simple reflection. 
     * 
     * @param g the group
     * @param simpleRoot the index of the simple root
     */
    public WeylElement(ExceptionalGroup g, int simpleRoot) {/*@\label{weconst}@*/
	group = g;
	word = new ArrayList<Integer>();
	word.add(simpleRoot);
    }/*@\label{weconstend}@*/
    
    private WeylElement(ExceptionalGroup g, List<Integer> l) {
	group = g;
	word = new ArrayList<Integer>(l);
    }
    
    @Override
    public WeylElement inverse() {
	
	
	return this;
    }

    @Override
    public WeylElement times(WeylElement arg0) {
	if (arg0.group != this.group)
	    throw new IllegalArgumentException(
		    "Elements not from same exceptional group.");
	word.addAll(arg0.word);
	return this;
    }

    /**
     * This returns the word associated with this Weyl element.
     * 
     *  @return the word
     */
    public List<Integer> getWord() {
	return word;
    }
    
    @Override
    public Object copy() {/*@\label{wecopy}@*/
	
	 return new WeylElement(group,word);
    }/*@\label{wecopyend}@*/
    
    public String toString() {
	StringBuffer sb = new StringBuffer();
	for (Integer i : word){
	    sb.append(i + " ");
	}
	return sb.toString();
    }

}
